package com.teamwings.modules.file.controller;


//import com.teamwings.common.vo.Result;
import com.teamwings.modules.file.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.file.api.feign.FileServiceFeign;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-05-06
 */
@RestController
@Api(tags = "文件服务")
@RequestMapping("/form/file")
@Slf4j
public class FileController {

    @Autowired
    private FileServiceFeign fileServiceFeign;

    @ApiOperation(value = "文件上传到文件服务", notes = "文件上传到文件服务")
    @PostMapping(value = "upload")
    public Result<?> upload(
            @RequestParam(value = "file") MultipartFile file,
            @RequestParam(value = "bizPath", required = false) String bizPath
    ) {
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String username = "admin";
        return fileServiceFeign.uploadFile(username, bizPath, file.getOriginalFilename(), file);
    }

    @ApiOperation(value = "文件列表下载", notes = "文件列表下载")
    @PostMapping(value = "downloadFiles")
    public void downloadFiles(
            HttpServletResponse response,
            @RequestParam(value = "bizPath") List<String> bizPath
    ) {
//        ossService.downloadFiles(bizPath, response);
//        fileServiceFeign.downLoadFiles(response, );
    }

//    @ApiOperation(value = "文件下载", notes = "文件下载")
//    @PostMapping(value = "downloadFile")
//    public void downloadFile(
//            HttpServletResponse response,
//            @RequestParam(value = "bizPath") String bizPath
//    ) {
//        ossService.downloadFile(bizPath, response);
//    }
}
